package com.sailfish.springbootdemo.service.db1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sailfish.springbootdemo.common.DB1EmailTemplates;
import com.sailfish.springbootdemo.common.StrToCompanys;
import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.dao.db1.*;
import com.sailfish.springbootdemo.dao.db4.UserDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.*;
import com.sailfish.springbootdemo.pojo.db2.MailAddress;
import com.sailfish.springbootdemo.pojo.db4.Operate;
import com.sailfish.springbootdemo.pojo.db4.User;
import com.sailfish.springbootdemo.service.db2.ThirdApiService;
import com.sailfish.springbootdemo.service.db4.OperateService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class PcbaSpecialResourceServiceImpl implements PcbaSpecialResourceService {

    @Autowired
    private PcbaSpecialResourceDao pcbaSpecialResourceDao;

    @Autowired
    private PcbaSpecialRelatedTechParamActualDao pcbaSpecialRelatedTechParamActualDao;
    @Autowired
    private PcbaCompanyDao pcbaCompanyDao;
    @Autowired
    private PcbaWorkshopDao pcbaWorkshopDao;
    @Autowired
    private PcbaDeviceTypeDao pcbaDeviceTypeDao;
    @Autowired
    private AuditHistoryDao auditHistoryDao;

    @Autowired
    private UserDao userDao;

    @Value("${personal.config.env}")
    private String env;

    @Autowired
    private ThirdApiService thirdApiService;

    @Value("${personal.config.sso.trusted-redirect-uri}")
    private String trustedRedirectUri;

    @Qualifier("MysqlTransactionManager1")
    @Autowired
    private DataSourceTransactionManager transactionManager1;

    @Autowired
    private OperateService operateService;

    private String operateSmallType = "其他工艺管理";

    @Autowired
    private StrToCompanys strToCompanys;

    @Override
    public Result getAllByDeviceTypeAndSearch(Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaDeviceTypeId, Integer page, Integer pageSize, Integer status) {
        try {
            if (page == null || !CommonUtils.isNumeric(page.toString())) {
                return ResultUtil.error(500, "错误参数page", "Error Param page", null);
            }
            if (pageSize == null || !CommonUtils.isNumeric(pageSize.toString())) {
                return ResultUtil.error(500, "错误参数pageSize", "Error Param pageSize", null);
            }
            int begin = (page - 1) * pageSize;

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            List<PcbaSpecialResource> list = pcbaSpecialResourceDao.getAllByDeviceTypeAndSearch(pcbaCompanyId, pcbaWorkshopId, pcbaDeviceTypeId, begin, pageSize, status, companyIdList);
            for (PcbaSpecialResource pcbaSpecialResource : list) {
                pcbaSpecialResource.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaSpecialResource.getPcbaCompanyId()));
                pcbaSpecialResource.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaSpecialResource.getPcbaWorkshopId()));
                pcbaSpecialResource.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaSpecialResource.getPcbaDeviceTypeId()));
            }
            List<PcbaSpecialResource> list2 = pcbaSpecialResourceDao.getAllByDeviceTypeAndSearch(pcbaCompanyId, pcbaWorkshopId, pcbaDeviceTypeId, null, null, status, companyIdList);
            return ResultUtil.tableSuccess(page, pageSize, list2.size(), list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    @Transactional(transactionManager = "MysqlTransactionManager1")
    public Result deleteById(Integer pcbaSpecialResourceId) {
        try {
            // 需同步删除特殊参数表
            if (pcbaSpecialResourceId == null || "".equals(pcbaSpecialResourceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaSpecialResourceId", "Miss Param pcbaSpecialResourceId", null);
            }

            // 判断 roadmap是否添加绑定逻辑【后面再说吧，roadmap可能需要大改】

            String userId = UserHeaderHolder.getUserId();
            PcbaSpecialResource oldPcbaSpecialResource = pcbaSpecialResourceDao.getPcbaSpecialResourceById(pcbaSpecialResourceId);

            pcbaSpecialResourceDao.deleteById(pcbaSpecialResourceId);
            pcbaSpecialRelatedTechParamActualDao.deleteBySpecialResourceId(pcbaSpecialResourceId);

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(oldPcbaSpecialResource), null));

            return ResultUtil.success(null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    @Transactional(transactionManager = "MysqlTransactionManager1")
    public Result addOrUpdatePcbaSpecialResource(String data) {
        try {

            String userId = UserHeaderHolder.getUserId();

            JSONObject jsonObject = JSONObject.parseObject(data);
            String mode = jsonObject.getString("mode");
            Integer status = Integer.parseInt(jsonObject.getString("status"));
            JSONArray jsonArray = jsonObject.getJSONArray("specialParamList");
            Date d = new Date();
            if (mode == null || "".equals(mode)) {
                return ResultUtil.error(500, "缺少参数mode", "Miss Param mode", null);
            }
            if (!("edit".equals(mode) || "add".equals(mode))) {
                return ResultUtil.error(500, "mode 参数错误", "mode Param Error", null);
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Integer pcbaDeviceTypeId = jsonObject.get("pcbaDeviceTypeId") != null && !"".equals(jsonObject.get("pcbaDeviceTypeId").toString()) ? Integer.parseInt(jsonObject.get("pcbaDeviceTypeId").toString()) : null;
            Integer pcbaCompanyId = jsonObject.get("pcbaCompanyId") != null && !"".equals(jsonObject.get("pcbaCompanyId").toString()) ? Integer.parseInt(jsonObject.get("pcbaCompanyId").toString()) : null;
            Integer pcbaWorkshopId = jsonObject.get("pcbaWorkshopId") != null && !"".equals(jsonObject.get("pcbaWorkshopId").toString()) ? Integer.parseInt(jsonObject.get("pcbaWorkshopId").toString()) : null;
            String beginTimeStr = jsonObject.get("beginTimeStr") != null && !"".equals(jsonObject.get("beginTimeStr")) ? jsonObject.get("beginTimeStr").toString() : null;
            String endTimeStr = jsonObject.get("endTimeStr") != null && !"".equals(jsonObject.get("endTimeStr")) ? jsonObject.get("endTimeStr").toString() : null;
            if (beginTimeStr == null || "".equals(beginTimeStr)) {
                return ResultUtil.error(500, "缺少参数beginTimeStr", "Miss Param beginTimeStr", null);
            }
            if (endTimeStr == null || "".equals(endTimeStr)) {
                return ResultUtil.error(500, "缺少参数endTimeStr", "Miss Param endTimeStr", null);
            }
            if ("edit".equals(mode)) {
                Integer pcbaSpecialResourceId = jsonObject.get("pcbaSpecialResourceId") != null && !"".equals(jsonObject.get("pcbaSpecialResourceId").toString()) ? Integer.parseInt(jsonObject.get("pcbaSpecialResourceId").toString()) : null;

                PcbaSpecialResource oldPcbaSpecialResource = pcbaSpecialResourceDao.getPcbaSpecialResourceById(pcbaSpecialResourceId);

                // 修改 tb_pcba_special_resource
                PcbaSpecialResource pcbaSpecialResource = new PcbaSpecialResource();
                pcbaSpecialResource.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                pcbaSpecialResource.setUpdateTime(d);
                pcbaSpecialResource.setSort(100);
                pcbaSpecialResource.setStatus(status);
                pcbaSpecialResource.setPcbaCompanyId(pcbaCompanyId);
                pcbaSpecialResource.setPcbaWorkshopId(pcbaWorkshopId);
                Date beginTime = format.parse(beginTimeStr);
                Date endTime = format.parse(endTimeStr);
                pcbaSpecialResource.setBeginTime(beginTime);
                pcbaSpecialResource.setEndTime(endTime);
                pcbaSpecialResource.setSubmitter(Integer.parseInt(userId));
                pcbaSpecialResource.setPcbaSpecialResourceId(pcbaSpecialResourceId);
                pcbaSpecialResourceDao.updatePcbaSpecialResource(pcbaSpecialResource);

                /*if(status == 1 || status == 2){
                    // 添加 审核记录
                    AuditHistory addAuditHistory = new AuditHistory();
                    addAuditHistory.setAuditType(2);
                    addAuditHistory.setCreateTime(d);
                    addAuditHistory.setSubmitUserId(Integer.parseInt(userId));
                    addAuditHistory.setAuditUserId(null);
                    addAuditHistory.setAuditStatus(status);
                    addAuditHistory.setAuditNotes(null);
                    addAuditHistory.setRelatedId(pcbaSpecialResourceId);
                    auditHistoryDao.addAuditHistory(addAuditHistory);
                }*/

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, new Date(), JSONObject.toJSONString(oldPcbaSpecialResource), JSONObject.toJSONString(pcbaSpecialResource)));

                List<PcbaSpecialRelatedTechParamActual> oldList = pcbaSpecialRelatedTechParamActualDao.getPcbaSpecialRelatedTechParamActualByResourceId(pcbaSpecialResourceId);
                //删除原先的关联表
                pcbaSpecialRelatedTechParamActualDao.deleteBySpecialResourceId(pcbaSpecialResourceId);

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(oldList), null));

                List<PcbaSpecialRelatedTechParamActual> list = new ArrayList<>();
                //再新增
                for (Object o : jsonArray) {
                    JSONObject jo = JSONObject.parseObject(o.toString());
                    String techDeviceParamKey = jo.getString("techDeviceParamKey");
                    String techDeviceParamValue = jo.getString("techDeviceParamValue");
                    PcbaSpecialRelatedTechParamActual pcbaSpecialRelatedTechParamActual = new PcbaSpecialRelatedTechParamActual();
                    pcbaSpecialRelatedTechParamActual.setCreateTime(d);
                    pcbaSpecialRelatedTechParamActual.setPcbaSpecialResourceId(pcbaSpecialResourceId);
                    pcbaSpecialRelatedTechParamActual.setTechDeviceParamKey(techDeviceParamKey);
                    pcbaSpecialRelatedTechParamActual.setTechDeviceParamValue(techDeviceParamValue);
                    pcbaSpecialRelatedTechParamActual.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                    pcbaSpecialRelatedTechParamActualDao.addPcbaSpecialRelatedTechParamActual(pcbaSpecialRelatedTechParamActual);
                    list.add(pcbaSpecialRelatedTechParamActual);
                }

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(list)));

                if (status == 3) {
                    //发送邮件
                    try {
                        List<User> userList = new ArrayList<>();
                        PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaCompanyId);
                        if (pcbaCompany != null) {
                            String emailOwners5 = pcbaCompany.getEmailOwners5();
                            if (emailOwners5 != null && !"".equals(emailOwners5)) {
                                String[] split = emailOwners5.split(",");
                                for (String s : split) {
                                    if (s.contains("/")) {
                                        String[] strings = s.split("\\/");
                                        if (strings.length == 2) {
                                            String domainAccount = strings[1];
                                            if (domainAccount != null && !"".equals(domainAccount)) {
                                                User u = userDao.getUserInfoByDomainAccount(domainAccount);
                                                if (u != null) {
                                                    userList.add(u);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        List<MailAddress> mailAddressList = new ArrayList<>();
                        for (User user : userList) {
                            if(user.getEmail().contains(",")){
                                String[] emailsArr = user.getEmail().split(",");
                                for (String email : emailsArr) {
                                    MailAddress mailAddress = new MailAddress();
                                    mailAddress.setMailAddress(email);
                                    mailAddress.setType(0);
                                    mailAddressList.add(mailAddress);
                                }
                            }else{
                                MailAddress mailAddress = new MailAddress();
                                mailAddress.setMailAddress(user.getEmail());
                                mailAddress.setType(0);
                                mailAddressList.add(mailAddress);
                            }
                        }

                        if (mailAddressList.size() > 0) {

                            String mailContent = "<html><body>" +
                                    "<p>主题：" + DB1EmailTemplates.SPECIAL_TECH_PARAMS_MAIL_CONTENT + "</p>" +
                                    "<p>所在工厂：" + pcbaCompany.getPcbaCompanyNameCn() + "</p>" +
                                    "<p>网页链接：" + "<a href='" + trustedRedirectUri + DB1EmailTemplates.SPECIAL_TECH_PARAMS_WEB_URL + "'>点击跳转</a>" +  "</p>" +
                                    "</html></body>";

                            Result result = thirdApiService.sendMail("", DB1EmailTemplates.SPECIAL_TECH_PARAMS_TITLE, DB1EmailTemplates.SPECIAL_TECH_PARAMS_MAIL_CONTENT_TITLE,
                                    mailContent, "10086", mailAddressList, null, null, null, null, 2, null);
                            if (result.getCode() == 200) {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("其他实际工艺能力邮件,发送成功");
                            } else {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("其他实际工艺能力邮件,发送失败:" + result.getMsgCn());
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                        System.out.println("其他实际工艺能力邮件：" + e.getMessage());
                    }
                }

                return ResultUtil.success(null);
            } else {
                // 同一工厂、车间、设备类型[特殊]只允许存在一个
                List<PcbaSpecialResource> pcbaSpecialResourceList = pcbaSpecialResourceDao.getAllByDeviceTypeAndSearch(pcbaCompanyId, pcbaWorkshopId, pcbaDeviceTypeId, null, null, null, null);
                if (pcbaSpecialResourceList.size() > 0) {
                    return ResultUtil.error(500, "当前工厂车间已存在该工艺，无法重复添加", "Already Exist", null);
                }
                // 添加 tb_pcba_special_resource
                PcbaSpecialResource pcbaSpecialResource = new PcbaSpecialResource();
                pcbaSpecialResource.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                pcbaSpecialResource.setCreateTime(d);
                pcbaSpecialResource.setSort(100);
                pcbaSpecialResource.setStatus(status);
                pcbaSpecialResource.setPcbaCompanyId(pcbaCompanyId);
                pcbaSpecialResource.setPcbaWorkshopId(pcbaWorkshopId);
                Date beginTime = format.parse(beginTimeStr);
                Date endTime = format.parse(endTimeStr);
                pcbaSpecialResource.setBeginTime(beginTime);
                pcbaSpecialResource.setEndTime(endTime);
                pcbaSpecialResource.setSubmitter(Integer.parseInt(userId));
                pcbaSpecialResourceDao.addPcbaSpecialResource(pcbaSpecialResource);

                if (status == 3) {
                    // 添加 审核记录
                    AuditHistory addAuditHistory = new AuditHistory();
                    addAuditHistory.setAuditType(2);
                    addAuditHistory.setCreateTime(d);
                    addAuditHistory.setSubmitUserId(Integer.parseInt(userId));
                    addAuditHistory.setAuditUserId(null);
                    addAuditHistory.setAuditStatus(status);
                    addAuditHistory.setAuditNotes(null);
                    addAuditHistory.setRelatedId(pcbaSpecialResource.getPcbaSpecialResourceId());
                    auditHistoryDao.addAuditHistory(addAuditHistory);
                }

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(pcbaSpecialResource)));

                List<PcbaSpecialRelatedTechParamActual> list = new ArrayList<>();
                for (Object o : jsonArray) {
                    JSONObject jo = JSONObject.parseObject(o.toString());
                    String techDeviceParamKey = jo.getString("techDeviceParamKey");
                    String techDeviceParamValue = jo.getString("techDeviceParamValue");
                    PcbaSpecialRelatedTechParamActual pcbaSpecialRelatedTechParamActual = new PcbaSpecialRelatedTechParamActual();
                    pcbaSpecialRelatedTechParamActual.setCreateTime(d);
                    pcbaSpecialRelatedTechParamActual.setPcbaSpecialResourceId(pcbaSpecialResource.getPcbaSpecialResourceId());
                    pcbaSpecialRelatedTechParamActual.setTechDeviceParamKey(techDeviceParamKey);
                    pcbaSpecialRelatedTechParamActual.setTechDeviceParamValue(techDeviceParamValue);
                    pcbaSpecialRelatedTechParamActual.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                    pcbaSpecialRelatedTechParamActualDao.addPcbaSpecialRelatedTechParamActual(pcbaSpecialRelatedTechParamActual);
                    list.add(pcbaSpecialRelatedTechParamActual);
                }

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(list)));

                return ResultUtil.success(null);
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result auditPcbaSpecialResource(Integer pcbaSpecialResourceId, String notes, Integer status) {
        try {
            if (pcbaSpecialResourceId == null || "".equals(pcbaSpecialResourceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaSpecialResourceId", "Miss Param pcbaSpecialResourceId", null);
            }
            if (notes == null || "".equals(notes.toString())) {
                return ResultUtil.error(500, "缺少参数notes", "Miss Param notes", null);
            }
            if (status == null || "".equals(status.toString())) {
                return ResultUtil.error(500, "缺少参数status", "Miss Param status", null);
            }

            String userId = UserHeaderHolder.getUserId();
            PcbaSpecialResource oldPcbaSpecialResource = pcbaSpecialResourceDao.getPcbaSpecialResourceById(pcbaSpecialResourceId);

            Date d = new Date();
            Integer integer = pcbaSpecialResourceDao.auditPcbaSpecialResource(pcbaSpecialResourceId, notes, status, d);
            if (integer > 0) {

                PcbaSpecialResource newPcbaSpecialResource = oldPcbaSpecialResource;
                newPcbaSpecialResource.setUpdateTime(d);
                newPcbaSpecialResource.setNotes(notes);
                newPcbaSpecialResource.setStatus(status);
                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, new Date(), JSONObject.toJSONString(oldPcbaSpecialResource), JSONObject.toJSONString(newPcbaSpecialResource)));

                // 添加 审核记录
                AuditHistory addAuditHistory = new AuditHistory();
                addAuditHistory.setAuditType(2);
                addAuditHistory.setCreateTime(d);
                addAuditHistory.setSubmitUserId(Integer.parseInt(userId));
                addAuditHistory.setAuditUserId(null);
                addAuditHistory.setAuditStatus(status);
                addAuditHistory.setAuditNotes(null);
                addAuditHistory.setRelatedId(pcbaSpecialResourceId);
                auditHistoryDao.addAuditHistory(addAuditHistory);

                // 发送邮件通知
                /*try{
                    List<User> userList = new ArrayList<>();
                    Integer pcbaCompanyId = oldPcbaSpecialResource.getPcbaCompanyId();
                    if(pcbaCompanyId != null){
                        PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaCompanyId);
                        if(pcbaCompany != null){
                            String emailOwners5 = pcbaCompany.getEmailOwners5();
                            if(emailOwners5 != null && !"".equals(emailOwners5)){
                                String[] split = emailOwners5.split(",");
                                for (String s : split) {
                                    if(s.contains("/")){
                                        String[] strings = s.split("\\/");
                                        if(strings.length == 2){
                                            String domainAccount = strings[1];
                                            if(domainAccount != null && !"".equals(domainAccount)){
                                                User u = userDao.getUserInfoByDomainAccount(domainAccount);
                                                if(u != null){
                                                    userList.add(u);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    List<MailAddress> mailAddressList = new ArrayList<>();
                    for (User user : userList) {
                        MailAddress mailAddress = new MailAddress();
                        mailAddress.setMailAddress(user.getEmail());
                        mailAddress.setType(0);
                        mailAddressList.add(mailAddress);
                    }
                    if(mailAddressList.size() > 0){
                        if(status == 1){
                            Result result = thirdApiService.sendMail("", DB1EmailTemplates.SPECIAL_TECH_PARAMS_TITLE_OK, DB1EmailTemplates.SPECIAL_TECH_PARAMS_MAIL_CONTENT_TITLE_OK,
                                    DB1EmailTemplates.SPECIAL_TECH_PARAMS_MAIL_CONTENT_OK, "10086", mailAddressList, null, null, null, null, 2, null);
                            if(result.getCode() == 200){
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("特殊实际工艺能力审核结果邮件,发送成功");
                            }else{
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("特殊实际工艺能力审核结果邮件,发送失败:" + result.getMsgCn());
                            }
                        }else if(status == 2){
                            Result result = thirdApiService.sendMail("", DB1EmailTemplates.SPECIAL_TECH_PARAMS_TITLE_NO, DB1EmailTemplates.SPECIAL_TECH_PARAMS_MAIL_CONTENT_TITLE_NO,
                                    DB1EmailTemplates.SPECIAL_TECH_PARAMS_MAIL_CONTENT_NO, "10086", mailAddressList, null, null, null, null, 2, null);
                            if(result.getCode() == 200){
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("特殊实际工艺能力审核结果邮件,发送成功");
                            }else{
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("特殊实际工艺能力审核结果邮件,发送失败:" + result.getMsgCn());
                            }
                        }
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                    System.out.println("特殊实际工艺能力审核结果邮件发送失败");
                }*/

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
